import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDLegionLevel {
	/**ID*/
	id,
	/**军团等级*/
	levelRank,
	/**名字*/
	name,
	/**描述*/
	desc,
	/**成员上限*/
	memberNum,
	/**下一级所需经验(0:无下一级）*/
	expNext,

	/**枚举数量*/
	EnumCount
}



export class CDLegionLevel{
	/**ID*/
	public id: number;
	/**军团等级*/
	public levelRank: number;
	/**名字*/
	public name: number;
	/**描述*/
	public desc: number;
	/**成员上限*/
	public memberNum: number;
	/**下一级所需经验(0:无下一级）*/
	public expNext: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDLegionLevel.id: return this.id;
			case E_CDLegionLevel.levelRank: return this.levelRank;
			case E_CDLegionLevel.name: return this.name;
			case E_CDLegionLevel.desc: return this.desc;
			case E_CDLegionLevel.memberNum: return this.memberNum;
			case E_CDLegionLevel.expNext: return this.expNext;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDLegionLevel.id: this.id = v; break;
			case E_CDLegionLevel.levelRank: this.levelRank = v; break;
			case E_CDLegionLevel.name: this.name = v; break;
			case E_CDLegionLevel.desc: this.desc = v; break;
			case E_CDLegionLevel.memberNum: this.memberNum = v; break;
			case E_CDLegionLevel.expNext: this.expNext = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDLegionLevel> = new HashMap<number, CDLegionLevel>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDLegionLevel[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDLegionLevel();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].levelRank = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].memberNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].expNext = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDLegionLevel{
		return this.datas ? this.datas.get(id) : null;
	}
}
